package org.kleathome.dcpu16;

import org.kleathome.dcpu16.emulator.Emulator;

public class DCPU16Sub extends DCPU16Instruction {

	@Override
	public String parseInstruction(String in)
	{
		return super.parseInstruction(in.trim().substring(4).trim());
	}

	@Override
	public int getCycleCost()
	{
		return 2 + super.getCycleCost();
	}

	@Override
	public int getOpCode()
	{
		return 0x03;
	}
	
	@Override
	public void execute()
	{
		char vA = valueA.getValue();
		char vB = valueB.getValue();
		if (vB > vA)
			Emulator.setRegister(Emulator.Registers.O, (char)1);
		valueA.setValue((char)(vA - vB));
	}

	@Override
	public String getOpCodeLiteral()
	{
		return "SUB";
	}
	@Override
	public DCPU16Instruction getNewObject()
	{
		return new DCPU16Sub();
	}
}
